﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 9:55 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace Miming.Model
{
	/// <summary>
	/// Description of Bill.
	/// </summary>
	public class Bill
	{
		int id;
		Vendor vendor;
		IList<BillItem> items = new List<BillItem>();
		
		public virtual IList<BillItem> Items {
			get { return items; }
			set { items = value; }
		}
		
		public virtual Vendor Vendor {
			get { return vendor; }
			set { vendor = value; }
		}
		bool billReceived;
		
		public virtual bool BillReceived {
			get { return billReceived; }
			set { billReceived = value; }
		}
		string vendorDetails;
		
		public virtual string VendorDetails {
			get { return vendorDetails; }
			set { vendorDetails = value; }
		}
		Terms terms;
		
		public virtual Terms Terms {
			get { return terms; }
			set { terms = value; }
		}
		string memo;
		
		public virtual string Memo {
			get { return memo; }
			set { memo = value; }
		}
		string refNo;
		
		public virtual string RefNo {
			get { return refNo; }
			set { refNo = value; }
		}
		DateTime billDue = DateTime.Now;
		
		public virtual DateTime BillDue {
			get { return billDue; }
			set { billDue = value; }
		}
		
		public virtual int Id {
			get { return id; }
			set { id = value; }
		}
		DateTime date = DateTime.Now;
		
		public virtual DateTime Date {
			get { return date; }
			set { date = value; }
		}
		
		public Bill()
		{
		}
		
		public virtual void AddItem(BillItem item)
		{
			item.Bill = this;
			items.Insert(0, item);
			OnItemAdded(null);
		}
		
		protected virtual void OnItemAdded(EventArgs e)
		{
			if (ItemAdded != null) {
				ItemAdded(this, e);
			}
		}
		
		public virtual event EventHandler ItemAdded;
	}
	
	public class BillItem
	{
		Item item;
		UnitOfMeasure unitOfMeasure;
		Customer customer;
		
		public virtual Customer Customer {
			get { return customer; }
			set { customer = value; }
		}
		bool billable;
		
		public virtual bool Billable {
			get { return billable; }
			set { billable = value; }
		}
		Class _class;
		
		public virtual Class Class {
			get { return _class; }
			set { _class = value; }
		}
		
		public virtual UnitOfMeasure UnitOfMeasure {
			get { return unitOfMeasure; }
			set { unitOfMeasure = value; }
		}
		double cost;
		
		public virtual double Cost {
			get { return cost; }
			set { cost = value; }
		}
		
		public virtual double Amount {
			get { return cost * quantity; }
		}
		
		public virtual Item Item {
			get { return item; }
			set { item = value; Cost = item.Cost; }
		}
		Bill bill;
		
		public virtual Bill Bill {
			get { return bill; }
			set { bill = value; }
		}
		double quantity;
		
		public virtual double Quantity {
			get { return quantity; }
			set { quantity = value; }
		}
		
		public BillItem()
		{
		}
		
		public BillItem(Item item) : this(item, 1)
		{
		}
		
		public BillItem(Item item, double quantity)
		{
			this.item = item;
			this.quantity = quantity;
		}
	}
}
